<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>维护 - UOJ部署指北</title>

	<!-- css -->
	<link href="/css/base.min.css" rel="stylesheet">
	<link href="/css/project.min.css" rel="stylesheet">
	<link href="/css/styles.css" rel="stylesheet">
	<link href="/css/gitalk.css" rel="stylesheet">

</head>
<body class="page-brand">
	
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">维护</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">维护</span>

		<ul class="nav nav-list pull-right">
			<li>
				<a data-toggle="menu" href="/">
					<span class="avatar avatar-sm"><img alt="logo" src="/img/logo.png"></span>
				</a>
			</li>
		</ul>

	</header>

	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="/">UOJ部署指北</a>
				<ul class="nav">
					<li>
					
						
							
							
								<a class="collapsed waves-attach waves-effect" data-toggle="collapse" href="#入门">入门</a>	
								<ul class="menu-collapse collapse in" id="入门">

								<li>
									<a class="waves-attach" href="/post/安装.html">安装</a>
								</li><li class="active">
									<a class="waves-attach" href="/post/维护.html">维护</a>
								</li><li>
									<a class="waves-attach" href="/post/外网映射教程.html">外网映射教程</a>
								</li><li>
									<a class="waves-attach" href="/post/系统管理.html">系统管理</a>
								</li></ul>
								<a class="collapsed waves-attach waves-effect" data-toggle="collapse" href="#题目">题目</a>	
								<ul class="menu-collapse collapse in" id="题目">

								<li>
									<a class="waves-attach" href="/post/题目管理概述.html">题目管理概述</a>
								</li><li>
									<a class="waves-attach" href="/post/传统题配置.html">传统题配置</a>
								</li><li>
									<a class="waves-attach" href="/post/特殊需求配置.html">特殊需求配置</a>
								</li><li>
									<a class="waves-attach" href="/post/数据检验器.html">数据检验器</a>
								</li><li>
									<a class="waves-attach" href="/post/答案检查器.html">答案检查器</a>
								</li></ul>
								<a class="collapsed waves-attach waves-effect" data-toggle="collapse" href="#开发">开发</a>	
								<ul class="menu-collapse collapse in" id="开发">

								<li>
									<a class="waves-attach" href="/post/SVN简易指北.html">SVN简易指北</a>
								</li><li>
									<a class="waves-attach" href="/post/本地构建镜像.html">本地构建镜像</a>
								</li><li>
									<a class="waves-attach" href="/post/贡献.html">贡献</a>
								</li></ul>
								<a class="collapsed waves-attach waves-effect" data-toggle="collapse" href="#关于">关于</a>	
								<ul class="menu-collapse collapse in" id="关于">

								<li>
									<a class="waves-attach" href="/post/关于.html">关于</a>
								</li></ul>						


					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<tit class="content-heading">维护</tit>
			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner page-card-inner">
						<h2>Docker简介</h2>
<p>之前说过，Docker 相当于一台虚拟机。</p>
<p>我们把虚拟机称作“容器（container）”，容器需要基于“镜像（image）”来运行。</p>
<h2>容器维护</h2>
<p>docker容器很容易维护。您只需要掌握以下命令：</p>
<div class="codehilite"><pre><span></span>docker start uoj                <span class="c1"># 启动 uoj 容器</span>
docker stop uoj                 <span class="c1"># 暂停 uoj 容器</span>
docker restart uoj              <span class="c1"># 重启 uoj 容器</span>

docker <span class="nb">exec</span> -it uoj /bin/bash   <span class="c1"># 进入 uoj 容器的终端</span>

docker commit uoj uoj_back:tag  <span class="c1"># 将 uoj 容器保存为标签为 tag 的 uoj_back 镜像</span>

docker ps -a                    <span class="c1"># 查看所有的容器</span>
docker images                   <span class="c1"># 查看所有的镜像</span>
docker rm uoj                   <span class="c1"># 删除 uoj 容器（慎用）</span>
docker rmi uoj_back:tag         <span class="c1"># 删除标签为 tag 的 uoj_back 镜像，</span>
</pre></div>


<p>在docker中，每个容器需要基于一个镜像来运行。最开始，我们的<code>uoj</code>容器是基于安装过程中构建的镜像。</p>
<p>下面是一次典型的数据恢复：</p>
<div class="codehilite"><pre><span></span>docker commit uoj uoj_back:20170101     <span class="c1"># 例行备份</span>
docker commit uoj uoj_back:20170201     <span class="c1"># 例行备份</span>
docker commit uoj uoj_back:20170301     <span class="c1"># 例行备份</span>

<span class="c1"># 3月15日，黑恶势力破坏了 uoj，uoj 容器已经无用，必须恢复</span>

docker stop uoj
docker rm uoj                           <span class="c1"># 删除uoj容器</span>
docker run --name uoj -dit -p <span class="m">80</span>:80 -p <span class="m">3690</span>:3690 --cap-add SYS_PTRACE  uoj_back:20170301
<span class="c1"># 创建新的 uoj 容器，使用3月1日的备份</span>
</pre></div>


<h2>数据迁移</h2>
<p>下面的命令可以把 <code>uoj_back</code> 这个容器导出为 <code>uoj.tar</code> 这个文件：</p>
<div class="codehilite"><pre><span></span>docker save -o uoj.tar uoj_back
</pre></div>


<p>把 <code>uoj.tar</code> 复制到其他机器上，然后可以运行下面的命令导入 <code>uoj_back</code> 镜像：</p>
<div class="codehilite"><pre><span></span>docker load --input uoj.tar
</pre></div>


<p>下面是一次典型的数据迁移：</p>
<div class="codehilite"><pre><span></span><span class="c1"># 服务器 A：</span>
docker commit uoj uoj_back              <span class="c1"># 把uoj容器存储为镜像</span>
docker save -o uoj.tar uoj_back         <span class="c1"># 把uoj_back镜像导出</span>
<span class="c1"># 然后通过某些恶毒的手段把 uoj.tar 拷到服务器 B</span>


<span class="c1"># 服务器 B：</span>
docker load --input uoj.tar             <span class="c1"># 导入uoj_back镜像</span>
docker run --name uoj -dit -p <span class="m">80</span>:80 -p <span class="m">3690</span>:3690 --cap-add SYS_PTRACE  uoj_back
<span class="c1"># 建立 uoj 容器，基于之前服务器 A 的数据，迁移完成</span>
</pre></div>


<p>接下来请您阅读《<a href="https://universaloj.github.io/post/系统管理.html">系统管理</a>》的相关内容。</p>
								<hr>

								<!-- Gitalk 评论框 start -->
								<div id="gitalk-container"></div>
								<!-- Gitalk 评论框 end -->

								</div>
							</div>
						</div>
					</section>
				</div>
			</div>

			
			<hr>
			<center>[CC协议 BY-NC-SA] 署名 - 非商业性使用 - 相同方式共享  @ UOJ部署指北 2018</center>

		</div>


	</main>
	
	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light" data-toggle="dropdown">
				<span class="fbtn-text fbtn-text-left">Home</span>
				<span class="fbtn-ori icon">apps</span>
				<span class="fbtn-sub icon">close</span>
			</a>
			<div class="fbtn-dropup">
				<a class="fbtn waves-attach waves-circle" href="https://github.com/UniversalOJ/UniversalOJ.github.io/issues" target="_blank">
					<span class="fbtn-text fbtn-text-left">反馈</span><span class="icon">feedback</span>
				</a>
				<a class="fbtn fbtn-green waves-attach waves-circle" href="/" target="_self">
					<span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span>
				</a>
			</div>
		</div>
	</div>

	

	<!-- js -->
	<script src="/js/jquery.min.js"></script>
	<script src="/js/base.min.js"></script>
    
    <!-- Gitalk JS 代码 start -->
    <script src="/js/gitalk.min.js"></script>
    <script>
    const gitalk = new Gitalk({
      clientID: '0dc093a9aefa1d501df2',
      clientSecret: '3639aabd1bc6b0d9b543be1f13b6bcb2bf7364af',
      repo: 'UniversalOJ.github.io',
	  id: location.pathname,
      owner: 'UniversalOJ',
      admin: ['cebarobot', 'MascoSkray', 'Ruanxingzhi', 'billchenchina'],
      labels: [],
    })
    
    gitalk.render('gitalk-container')
    </script>
    <!-- Gitalk JS 代码 end -->
    
</body>
</html>
